<script lang="ts" setup>
import { formRule } from './rule'
import type { JobType, JobWriteParamsType } from '../utils/model'

type Props = {
  data?: JobType
}
// 表单Ref

const formRef = ref()
// props
const { data } = defineProps<Props>()
// 表单数据
const formState = ref<JobWriteParamsType>({
  jobName: '',
  jobGroup: 'DEFAULT',
  invokeTarget: '',
  cronExpression: '',
  misfirePolicy: 3,
  concurrent: 0,
  status: 0,
  remark: ''
} as JobWriteParamsType)

// 判断是否是修改
if (data) {
  Object.assign(formState.value, data)
}
function getRef() {
  return formRef.value
}

defineExpose({ getRef })
</script>

<template>
  <a-form
    ref="formRef"
    :labelCol="{ style: { width: '95px' } }"
    :model="formState"
    :rules="formRule"
    label-align="left"
    style="margin-top: 15px"
  >
    <a-row :gutter="30">
      <a-col :span="12">
        <a-form-item label="任务名称" name="jobName">
          <a-input v-model:value="formState.jobName" placeholder="请输入任务名称" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <SpDict
          v-model="formState.jobGroup"
          dictType="sys_job_group"
          label="任务分组"
          name="jobGroup"
          placeholder="请选择任务分组"
          type="select"
        />
      </a-col>
      <a-col :span="24">
        <a-form-item label="调用目标" name="invokeTarget">
          <a-input v-model:value="formState.invokeTarget" placeholder="请输入调用字符串" />
        </a-form-item>
      </a-col>
      <a-col :span="24">
        <a-form-item label="cron表达式" name="cronExpression">
          <a-input v-model:value="formState.cronExpression" placeholder="请输入cron表达式" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <SpDict
          v-model="formState.status"
          dictType="sys_job_status"
          label="任务状态"
          name="jobGroup"
          type="radio"
        />
      </a-col>
      <a-col :span="12">
        <SpDict
          v-model="formState.concurrent"
          dictType="sys_job_concurrence_status"
          label="是否并发"
          name="concurrent"
          type="radio"
        />
      </a-col>
      <a-col :span="24">
        <SpDict
          v-model="formState.misfirePolicy"
          dictType="sys_job_error_strategy"
          label="错误策略"
          name="misfirePolicy"
          type="radio"
        />
      </a-col>
      <a-col :span="24">
        <a-form-item label="备注" name="remark">
          <a-textarea v-model:value="formState.remark" placeholder="请输入备注" />
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
</template>

<style scoped></style>
